
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/layout'
    },
    {
      path: '/layout',
      component: () => import('@/views/Layout/Layout.vue'),
      redirect: '/home',
      children: [
        {
          path: '/home',
          component: () => import('@/views/Home/index.vue')
        },
        {
          path: '/teacherInformation',
          component: () => import('@/views/CampusManager/TeacherInformation.vue')
        },
        {
          path: '/studentInformation',
          component: () => import('@/views/CampusManager/StudentInformation.vue')
        },
        {
          path: '/allTopic',
          component: () => import('@/views/SelectTopicManager/AllPublishTopic.vue')
        },
        {
          path: '/publish',
          component: () => import('@/views/SelectTopicManager/PublishTopic.vue')
        },
        {
          path: '/viewDetail',
          component: () => import('@/views/ThesisSubmit/ViewDetail.vue')
        },
        {
          path: '/uploadThesis',
          component: () => import('@/views/ThesisSubmit/UploadThesis.vue')
        },
      ]
    },
    {
      path: '/login',
      component: () => import('@/views/Login/Login.vue')
    },
    {
      path: '/:patchMatch(.*)*',
      component: () => import('@/views/NotFound/NotFound.vue')
    },

  ]
})

router.beforeEach((to, from, next) => {

  //对于登录页面不拦截
  if (to.path === '/login') {
    next();
  } else {
    // let loginAuthentication = roleInfo.isLogin
    let isLogin = sessionStorage.getItem('isLogin')
    console.log("isLogin" + isLogin);
    //用户访问认证后页面时 必须校验用户信息是否存在，不存在去登陆页
    if (isLogin) {
      next();
    } else {
      next('/login');
    }
  }
});

export default router
